﻿using System.Collections.Generic;
using System.Collections.ObjectModel;
using ScrappyDB.BaseClasses;
using ScrappyDB.Utilities;
using ScrappyDB.Linq;

namespace ScrappyDB.IntegrationTests.AwsQuery101Examples
{
    /************************************************************************************
    *   Query 101: Building Amazon SimpleDB Queries
    *   Sample Data    
    *   Source document: http://aws.amazon.com/articles/1231
    *************************************************************************************/
    public static class SampleData
    {
        public static void CreateSampleData()
        {
            var db = new Db();
            var books = new ScrappyDB.BaseClasses.SdbCollection<Book>();
            books.AddRange(new List<Book>
                            {
                                new Book()
                                    {
                                        Id = "0385333498",
                                        Title = "The Sirens of Titan",
                                        Author = "Kurt Vonnegut",
                                        Year = "1959",
                                        YearInt = 1959,
                                        NumberOfPages = 336,
                                        Keywords = new List<string>{"Book", "Paperback"},
                                        Rating = new List<string>{"*****", "5 stars", "Excellent"}
                                    },
                                new Book()
                                    {
                                        Id = "0802131786",
                                        Title = "Tropic of Cancer",
                                        Author = "Henry Miller",
                                        Year = "1934",
                                        YearInt = 1934,
                                        NumberOfPages = 318,
                                        Keywords = new List<string>{"Book"},
                                        Rating = new List<string>{"****"}
                                    },
                                new Book()
                                    {
                                        Id = "1579124585",
                                        Title = "The Right Stuff",
                                        Author = "Tom Wolfe",
                                        Year = "1979",
                                        YearInt = 1979,
                                        NumberOfPages = 304,
                                        Keywords = new List<string>{"Book", "Hardcover", "American"},
                                        Rating = new List<string>{"****", "4 stars"}
                                    },
                                new Book()
                                    {
                                        Id = "B000T9886K",
                                        Title = "In Between",
                                        Author = "Paul Van Dyk",
                                        Year = "2007",
                                        YearInt = 2007,
                                        Keywords = new List<string>{"CD", "Trance"},
                                        Rating = new List<string>{"4 stars"}
                                    },
                                new Book()
                                    {
                                        Id = "B00005JPLW",
                                        Title = "300",
                                        Author = "Zack Snyder",
                                        Year = "2007",
                                        YearInt = 2007,
                                        Keywords = new List<string>{"DVD", "Action", "Frank Miller"},
                                        Rating = new List<string>{"***", "3 stars", "Not bad"}
                                    },
                                new Book()
                                    {
                                        Id = "B000SF3NGK",
                                        Title = "Heaven's Gonna Burn Your Eyes",
                                        Author = "Thievery Corporation",
                                        Year = "2002",
                                         YearInt = 2002,
                                        Rating = new List<string>{"*****"}
                                    }
                            });

            books.SaveChanges();
        }

        public static void DeleteSampleData()
        {
            var db = new Db();
            var all = db.Query<Book>();
            for (int x = all.Count - 1; x >= 0; x--)
            {
                all.Remove(all[x]);
            }
        }
    }

    public class AwsSampleContext : SdbContext
    {
        public SdbSet<Book> Books { get; set; }
    }

    public class Book
    {
        public string Id { get; set; }
        public string Title { get; set; }
        public string Author { get; set; }
        public string Year { get; set; }
        public int YearInt { get; set; }
        public int NumberOfPages { get; set; }
        public List<string> Keywords { get; set; }
        public List<string> Rating { get; set; }
    }
}
